package com.zhhs.project.act.activity.controller;


import com.zhhs.common.utils.poi.ExcelUtil;
import com.zhhs.framework.aspectj.lang.annotation.Log;
import com.zhhs.framework.aspectj.lang.enums.BusinessType;
import com.zhhs.framework.web.controller.BaseController;
import com.zhhs.framework.web.domain.AjaxResult;
import com.zhhs.framework.web.page.TableDataInfo;
import com.zhhs.project.act.activity.domian.ActUser;
import com.zhhs.project.act.activity.service.IActUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户基本信息Controller
 *
 * @author zhhs
 * @date 2022-11-09
 */
@Controller
@RequestMapping("/wecom/activity/user")
public class ActUserController extends BaseController
{
    private String prefix = "activity/user";

    @Autowired
    private IActUserService actUserService;
    @PreAuthorize("@ss.hasPermi('activity:user:view')")
    @GetMapping()
    public String user()
    {
        return prefix + "/user";
    }

    /**
     * 查询用户基本信息列表
     */

    @PreAuthorize("@ss.hasPermi('activity:user:list')")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ActUser actUser)
    {
        startPage();
        List<ActUser> list = actUserService.selectActUserList(actUser);
        return getDataTable(list);
    }

    /**
     * 导出用户基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('activity:user:export')")
    @Log(title = "用户基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ActUser actUser)
    {
        List<ActUser> list = actUserService.selectActUserList(actUser);
        ExcelUtil<ActUser> util = new ExcelUtil<ActUser>(ActUser.class);
        return util.exportExcel(list, "用户基本信息数据");
    }

    /**
     * 新增用户基本信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户基本信息
     */
    @PreAuthorize("@ss.hasPermi('activity:user:add')")
    @Log(title = "用户基本信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ActUser actUser)
    {
        return toAjax(actUserService.insertActUser(actUser));
    }

    /**
     * 修改用户基本信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ActUser actUser = actUserService.selectActUserById(id);
        mmap.put("actUser", actUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户基本信息
     */
    @PreAuthorize("@ss.hasPermi('activity:user:edit')")
    @Log(title = "用户基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ActUser actUser)
    {
        return toAjax(actUserService.updateActUser(actUser));
    }

    /**
     * 删除用户基本信息
     */
    @PreAuthorize("@ss.hasPermi('activity:user:remove')")
    @Log(title = "用户基本信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(actUserService.deleteActUserByIds(ids));
    }
}
